	 /**************定义常量 *************/
	

/**
**2016年10月14日
**/
//;(function($){中间
//全部重新画完后需要设置平面
var drawAfterCenterNode=null;
	$.fn.Zupuclose =function(obj,winds){
		$(obj).live('click',function(){
			$(winds).remove();
		})
	}
	$.fn.Zupuhover =function(obj,clasName) {
		$(obj).hover(function(){
			$(this).addClass(clasName);
		},function(){
			$(this).removeClass(clasName);
		});
	};
	
	$.fn.Zupuclick =function(obj,clasName) {
		$(obj).live('click',function(){
			$(this).addClass(clasName).siblings().removeClass(clasName);
		})
	};
	
	$.fn.ZuputabId =function(obj,idobj,clasName,submenu_obj) {
		$(obj).live('click',function(){
			$(idobj).addClass(clasName).siblings().removeClass(clasName);
			$(submenu_obj).css({left:"0"});
			//$(this).parents(".container").addClass("ctr-figure-curr").siblings(".container").removeClass("ctr-figure-curr");		
		})
	};
	
	//内容高度自动
	$.fn.Zupubody =function(){
		var top_height = $(".location").outerHeight();
		var window_height = $(window).outerHeight() - top_height;
		$("#cont-body").css({"height":window_height + 'px'});
	}

	//复选单选美化
    $.fn.Zupuradio = function(options){
        var self = this;
        return $(':radio+label',this).each(function(){
			var us_name = $("#hidden_user_sex").prop('name');
			if(us_name == "person-frame-male"){//if为男性
				$('.btn-group').find("label:first").addClass("active");
				$(".btn-group").find("input")[0].checked = true;
			}else if(us_name == "person-frame-female"){//if为女性
				$('.btn-group').find("label:last").addClass("active");
				$(".btn-group").find("input")[1].checked = true;
			}
            if($(this).prev().is("checked"))
                $(this).addClass('active');
        }).live('click',function(event){
            $(this).siblings().removeClass("active");
            if(!$(this).prev().is(':checked')){
				$(this).addClass("active");
                $(this).prev()[0].checked = true;
            }
            event.stopPropagation();
        })
        .prev().hide();
    }
	var setImage=false;
	//图片上传预览    IE是用了滤镜。
	function previewImage(file) {
        setImage=true;
		var MAXWIDTH = 100;
		var MAXHEIGHT = 100;
		var div = document.getElementById('preview');
        document.getElementById("imghead").src = "/uploads/data-loading.gif";
        html5Reader(file);
	}
    //动态上传头像 
	function postAvatar(img) {
        if(setImage)
        {
	        var canvas = document.createElement("canvas");
	        canvas.width = 200;
	        canvas.height = 200;
	        var context = canvas.getContext("2d");
	        context.drawImage(img, 0, 0);
	        var imageData = canvas.toDataURL('image/png');
	        console.log(imageData);
	        $.post("/index.php?a=member&type=uploadavatar&ispost=1&otheravatar=1", { 'src': imageData, 'token': $token }, function (e) {
	            e = jQuery.parseJSON(e);
	            if (e.success) {
	                console.log(e.src);
	                var src = e.src;
	                img.src = src;
                    setImage=false;
	            }
	            else {
	                jpAlter(e.message);
	            }
	        })
        }
    }

    
    function html5Reader(file) {
        var file = file.files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            //上传图片 转化链接地址
            $.post("/index.php?a=member&type=uploadavatar&ispost=1&otheravatar=1", { 'src': this.result, 'token': $token }, function (e) {
                uploadingImage = false;
                e = jQuery.parseJSON(e);
                if (e.success) {
                    console.log(e.src);
                    var src = e.src;
                    document.getElementById("imghead").src = src;
                    
                }
                else {
                    alter(e.message);
                }
            })
        }
    }
	function clacImgZoomParam(maxWidth, maxHeight, width, height) {
		var param = {
			top: 0,
			left: 0,
			width: width,
			height: height
		};
		if (width > maxWidth || height > maxHeight) {
			rateWidth = width / maxWidth;
			rateHeight = height / maxHeight;
	
			if (rateWidth > rateHeight) {
				param.width = maxWidth;
				param.height = Math.round(height / rateWidth);
			} else {
				param.width = Math.round(width / rateHeight);
				param.height = maxHeight;
			}
		}
		param.left = Math.round((maxWidth - param.width) / 2);
		param.top = Math.round((maxHeight - param.height) / 2);
		return param;
	}


	 
	
	 //创建节点  自定义 函数
	 function jtCreateNode(sex) {
		 var n = new jpnode();
		 n.sex = sex;
		 n.id = jpnodes.length + 1;
		 return n;
	 }
	
	
	 //自定义消息弹框
	 var jpAlter = function (message) {
		 alert(message);
	 }
	

	
	 var jpnodes = [];

    var addChoiceBox=function(){
        var node = snode;
            if(snode.gene==0 || snode.gene==1){
               $(".addFather,.addMother,.addBrother,.addSiseter").addClass("name-disabled").unbind("click");   
            }
            if(node.father) 
            {
                $(".addFather").addClass("name-disabled").unbind("click");   
            }
            else{
                if(snode.id== $root.id)
                {
                        $(".addFather").removeClass("name-disabled");
                }    
            }
            if(node.mother || snode.id== $root.id) $(".addMother").addClass("name-disabled").unbind("click");
            if(node.sex==0 && node.spouse.length>0)$(".addHusband").addClass("name-disabled").unbind("click");
            if(node.sex==0){ $(".addWife").addClass("name-disabled").unbind("click");}else{$(".addHusband").addClass("name-disabled").unbind("click");}
    }
    var $container = $(".content-tree-box");
	 //启用
	 $(function () {
	     //添加新人物按钮弹框
	     var _figurehtml = '<div class="add-figure-box frame-windows">' +
			'<div class="add-figure-box-bg"></div>' +
			'<div class="add-figure-box-txt">' +
				'<div class="ico-closed">&times;</div>' +
				'<ul>' +
					'<li class="add-node name name-boy addFather" ship="2">父亲</li>' +
					'<li class="add-node name name-girl addMother" ship="3">母亲</li>' +					
				
					'<li class="add-node name name-boy addSon" ship="7">儿子</li>' +
					'<li class="add-node name name-girl addDaughter" ship="8">女儿</li>' +
					'<li class="add-node name name-boy addBrother" ship="4">兄弟</li>' +
					'<li class="add-node name name-girl addSiseter" ship="5">姐妹</li>' +
                    '<li class="add-node name name-boy addHusband addSpouse" ship="1">丈夫</li>' +
                    '<li class="add-node name name-girl addWife addSpouse" ship="6">妻子</li>' +
				'</ul>' +
			'</div>' +
		'</div>';

         //排序
         var _sorthtml='<div class="option-edit-box frame-windows">' +
			'<div class="option-edit-box-bg"></div>' +
			'<div class="option-edit-box-modal">' +
				'<div class="option-edit-box-main">' +
                    '<div class="mt">' +
						'<span>更新排序</span>' +
						'<i class="ico-closed">&times;</i>' +
					'</div>' +
					'<div class="mc">' +
						'<div class="item datum">' +
							
							'<div class="collapse">' +
							'<div class="form-group"><label>新排序</label><div><input placeholder="0-99" type="text" class="nodesort"></div></div>' +
							'</div>' + '<div class="form-group"><button class="btn btn-orange  btn-sort-save" type="button" >保存</button></div>' +
						'</div>' +
					'</div>' +
				'</div>' +
			'</div>' +
		'</div>'; 

   

	     //点击姓名加号追加-新人物按钮弹框
	     $(".ctr-figure-more,.ctr-figure-name,.ctr-figure-more-bg").live('click', function () {
             $("#cont-body").prepend(_figurehtml);
             $(".add-node").removeClass("name-disabled");
             var id =$(this).closest(".container").attr('nodeid');
             addChoiceBox();

	     })
          //编辑人物
	     $(".edit-button").live('click', function () {
            if($(this).hasClass("name-disabled"))
            {
                return ;
            }
             if(typeof($zpNodes)!= "undefined")
             {
                nodeDetail("edit",snode.id,0,snode.sort);
                return ;
             }
	     })

          
         $(".btn-sort-save").live("click",function(){
            var sort= snode.sort;
            var nsort= parseInt($(".nodesort").val());
            if(nsort<0) nsort=0;
            if(sort!=nsort)
            {
                var parent =snode.getParent();
                if(nsort>parent.childrens.length)
                {
                    nsort= parent.childrens.length;
                }
                var toxiao= nsort<sort;
                var ids=[],sorts=[];
                ids[0]=snode.id;
                sorts[0]=nsort;
                for(var j=0;j<parent.childrens.length;j++)
                {
                    var n = parent.childrens[j];
                    if(n==snode){continue;}
                    var id=n.id ,s= n.sort;                    
                    if(toxiao)
                    {
                        if(s>=nsort && s<sort){
                            s= s+1;
                        }
                    }
                    else{
                        if(s>sort && s<=nsort){
                            s--;
                        } 
                    }
                    ids[ids.length]=id;
                    sorts[sorts.length]= s;
                }
                $.getJSON('/index.php?a=ajax&type=sortJiapuNode&token=' + $token, 
                 {  
                    'ids':ids.join(","),
                    'sorts':sorts.join(","),
                    'nodeid':snode.id,
                    'jiapu':$jiapu.id,
                },
                function(e){
                    if(e.success)
                    {
                        snode.setSortOut(nsort);
                        jtMessageBox("排序已调整成功");
                        $(".option-edit-box").remove(); //移除追加人物编辑框
                    }
                    else{
                        jpAlter(e.message);
                    }
                });
                return ;
            }
            $(".option-edit-box").remove(); //移除追加人物编辑框
         }); 
	     //个人资料展示隐藏
	     $(".datum .title").live('click', function () {
	         $(".collapse").slideToggle("slow");
	         $(this).toggleClass("offon");
	     })

	     //左侧栏点击收起
	     $(".smbi-top .i-closed").live('click', function () {
	         $(".sub-menu-box").removeAttr("style");
	     })

	     //新增人物弹框选项-点击人物选项
	     $(".add-figure-box-txt .name").live('click', function () {
             if($(this).hasClass("name-disabled"))
            {
                return ;
            }
             if(typeof($zpNodes)!= "undefined")
             {
                var ship =$(this).attr("ship");
                var sort= 1;
                
                switch(ship){
                    case "1":
                    case "6":
                        sort= snode.spouse.length+1;
                        break;
                    case "4":
                    case "5":
                        var p =snode.getParent();
                        if(p){
                            sort=p.childrens.length+1;
                        }else{
                            sort=2;
                        }
                        break;
                    case "7":
                    case "8":
                        //sort= snode.childrens.length+1;
                        var hus =snode;
                        if(snode.sex==0){
                            var hus=snode.spouse[0];
                        }
                        if(hus)
                        {
                            sort=0;
                            for(var r=0;r<hus.childrens.length;r++){
                                var n =hus.childrens[r];
                                var cn= $nodes[n.id];
                                if(cn.father== hus.id){
                                    sort++;
                                }
                            }
                            for(var j=0;j<hus.spouse.length;j++){
                                    for(var t1=0;t1<hus.spouse[j].childrens.length;t1++){
                                        var n =hus.spouse[j].childrens[t1]; 
                                        var cn= $nodes[n.id];
                                        if(cn.father== hus.id){
                                            sort++;
                                        }
                                    }
                                   
                            }
                            sort+=1;
                        }
                        break;
                }
                
                nodeDetail("add",snode.id,ship, sort);
                return ;
             } 
	     });
          
         //清理输入框
         var clearBox=function(){
             $("[name=frm_name]").val("");
	         $("[name=frm_iphone]").val("");
	         $("[name=frm_description]").val("");
	         $(".birthstr").val("");
	         $(".work").val("");
	         $(".education").val("");
             $('.school').val("");
           
         }   
	     $(".extendParent").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
             drawAfterCenterNode= $nodes[snode.id];
	         snode.extendParent();
	     });
	     $(".extendChildren").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
             drawAfterCenterNode= $nodes[snode.id];
	         snode.extendChildren();
	     });
	     $(".intendParent").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
             drawAfterCenterNode= $nodes[snode.id];
	         snode.intendParent();
	     });
	     $(".intendChildren").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
             drawAfterCenterNode= $nodes[snode.id];
	         snode.intendChildren();

	     });
	     $(".intendAll").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
             drawAfterCenterNode= $nodes[snode.id];
	         snode.intendAllOut();
	     });
	     $(".extendAll").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
             drawAfterCenterNode= $nodes[snode.id];
	         snode.extendAllOut();
	     });
	     $(".delNode").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
           
             if(snode.id== $root.id){
                jtAlter("根节点不能删除");
                return false;
             }
	         if (snode.del()) {
	             snode = null;
	         }
	     })
	     $(".allMove").click(function () {
	         allMove($(".movex").val(), $(".movey").val());
	         //moveRight(x);
	     });
	     $(".nodeSort").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
	         var id = snode.id;
	         snode.setSortOut($(".sort").val());
	         var div = $("[nodeid=" + id + "]").trigger("click");
	     });

	     $(".siblings").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
	         var r = snode.siblings();
	         jpAlter("共有【" + r.length + "】个兄弟姐妹");
	     });
	     $(".isSiblingsFirst").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
	         var r = snode.isSiblingsFirst();
	         jpAlter("是否兄弟姐妹中的第一个:" + (r ? "是" : "否"));
	     });
	     $(".isSiblingsLast").click(function () {
	         if (snode == null) {
	             jpAlter('请选择有效的节点');
	             return;
	         }
	         var r = snode.isSiblingsLast();
	         jpAlter("是否兄弟姐妹中的最后一个:" + (r ? "是" : "否"));
	     });

	     $.fn.Zupubody();
	     $.fn.Zupuclose(".ico-closed", ".frame-windows");
	     $.fn.Zupuclick(".smbi-tab>.item", "seleced-cur");
	     $.fn.ZuputabId(".ctr-figure-image", "#user-index", "seleced-cur", ".sub-menu-box");
	     $.fn.ZuputabId(".item-class-index", "#user-index", "seleced-cur", ".sub-menu-box");
	     //$.fn.ZuputabId(".item-class-zupu", "#user-zupu", "seleced-cur", ".sub-menu-box");
	     //$.fn.ZuputabId(".item-class-ziliao", "#user-ziliao", "seleced-cur", ".sub-menu-box");
	     $.fn.ZuputabId(".item-class-jilu", "#user-jilu", "seleced-cur", ".sub-menu-box");
         $(".node-sort").live("click",function(){
             $(".tree_main").prepend(_sorthtml);
             $(".nodesort").val(snode.sort);
	         $('.btn-group').Zupuradio();
         });
         $(".node-extend").live("click",function(){
             snode.extendAllOut();
             removeBox(); 
             //setNodeCenter(snode);
        });
        $(".node-intend").live("click",function(){
            snode.intendAllOut();
            removeBox();
            //snode=
            //setNodeCenter(snode);
        });
        $(".node-delete").live("click",function(){
                 if (snode == null) {
	                 jpAlter('请选择有效的节点');
	                 return;
	             }
           
                 if(snode.id== $root.id){
                    jpAlter("根节点不能删除");
                    return false;
                 }
                $.getJSON('/index.php?a=ajax&type=deleteJiapuNode&token=' + $token+"&nodeid="+snode.id, 
                    function(e){
                        if(e.success)
                        {
                            snode.deleteNode(1);
                            removeBox(); 
                        }
                        else{
                            jpAlter(e.message);
                        }
               });
        });

	 });
	
	$(window).resize(function() {
		$.fn.Zupubody();
	});
     

   function sleep(numberMillis) {
　　    var now = new Date();
　　    var exitTime = now.getTime() + numberMillis;
　　    while (true) {
　　        now = new Date();
　　        if (now.getTime() > exitTime)
　　        return;
　　    }
　　}

var removeBox=function(){
     $(".option-edit-box").remove(); //移除追加人物编辑框
     jpdraw();
     links();
}

     
     //添加节点
    function addNodes(db, node) {

        if (drawed[node.id]) {
            return;
        }
        drawed[node.id] = node;
        var father = $nodes[db.father];
        var mother = $nodes[db.mother];
        if (father) {
            if (drawed[db.father]) {
                father = drawed[db.father]; 
            }
            else {
                father = db2treeNode(father); 
            } 
        }
        if (mother) {
            if (drawed[db.mother]) 
            { mother = drawed[db.mother]; } 
            else { mother = db2treeNode(mother); }  
        }

        if (drawed[db.father] || drawed[db.mother]) {
            if (mother && !father) {
                mother.addChildern(node);
            }
            else {
                father.addChildern(node, mother);
            }
        }
        else {
            if (father && mother) {
                node.addFather(father, mother);
                addNodes($nodes[db.father], father);
                addNodes($nodes[db.mother], mother);
            }
            else if (mother) {
                node.addFather(mother);
                addNodes($nodes[db.mother], mother);
            }
            else if (father) {
                node.addFather(father);
                addNodes($nodes[db.father], father);
            }
        }
           
        var spouse = $nodes[db.spouse];
        if (spouse) {
            if (drawed[spouse.id]) {
                var a =drawed[spouse.id];
                if(a.spouse.indexOf(node)<0)
                {
                    drawed[spouse.id].addSpouse(node);
                }
            }
            else {
                spouse = db2treeNode(spouse);
                node.addSpouse(spouse);
                addNodes($nodes[spouse.id], spouse);
            }
        }
    }
    function db2treeNode(dbNode) {
        var node ;
        if(nodesById[dbNode.id]){
            node= nodesById[dbNode.id];
        }
        else
        {
            node = new jpnode();
        }
        node.id = dbNode.id;
        
        node.avatar = dbNode.avatar;
        node.work = dbNode.work;
        node.mobile = dbNode.mobile;
        node.birthstr = dbNode.birthstr;
        node.name=getJPShowName(dbNode).replace(/\|/g,"　");
        node.intro = dbNode.intro;
        node.education = dbNode.education;
        node.sex = dbNode.sex;
        node.school=dbNode.school;
        node.summay=dbNode.summay;
        node.zibeitext=dbNode.zibeitext;
        node.sort= dbNode.brothersort? parseInt(dbNode.brothersort):(dbNode.spousesort?parseInt( dbNode.spousesort):0);
        //node.gene = dbNode.shidai;
        nodesById[node.id]= node;
        return node;
    }

    var jtMessageBox=function(message){
        jpAlter(message);
    };
        var callBackShowNode=function(node){
            afterDbSave=true;
            console.log('callback');
            $(".add-figure-box").remove();
            console.log('go add callback '+new Date().toTimeString());
            if(goAction=="add" && goType==2){
                window.location.reload();
                return ;
            }
                
                var action =node.action;
                var sptype= node.sptype;
                var node1 =db2treeNode(node);
                if(node.action=='add'){
                    node1.setBeforeNode(snode);
                    $("[nodeid="+snode.id+"]").find(".node-delete").remove();
                }
                //处理节点信息
                var shidai= node.shidai;
                if($("[scalegene="+shidai+"]").length==0){
                    addShidaiNav(shidai);
                }
                drawed[node.id] = node;
                switch(node.action)
                {
                    case 'add':
                       
                        $(".all-number").text(parseInt($(".all-number").val()+1));
                        $(".view-total").text(parseInt($(".view-total").val()+1));
                        // 添加父母
                        switch(node.sptype)
                        {
                            case "1":
                                snode.addSpouse(node1);
                                $(".option-edit-box").remove(); //移除追加人物编辑框
                                //removeBox();
                                break;
                            case "2":
                            case "3":
                                var f,m;
                                for(var n=0;n<nodes.length;n++)
                                {
                                    if(nodes[n].sptype==2)
                                    {
                                        f=nodes[n];
                                        f.add=true;
                                    }
                                    if(nodes[n].sptype==3)
                                    {
                                        m=nodes[n];
                                        m.add=true;
                                    }
                                }
                                if(f && f.add) f=null;
                                if(m && m.add) m=null;
                                if(f || m)
                                {
                                    if(f) f=db2treeNode(f);
                                    if(m)m=db2treeNode(m);   
                                    snode.addFather(f,m);
                                    $(".option-edit-box").remove(); //移除追加人物编辑框
                                    //removeBox();
                                }
                                break;
                            case "4":
                                snode.father.addSon(node1,snode.mother);
                               $(".option-edit-box").remove(); //移除追加人物编辑框
                                //removeBox();
                                break;
                            case "5":
                                snode.father.addDaughter(node1,snode.mother);
                                $(".option-edit-box").remove(); //移除追加人物编辑框
                                //removeBox();
                                break;
                            case "6":
                                snode.addSpouse(node1);
                                $(".option-edit-box").remove(); //移除追加人物编辑框
                                //removeBox();
                                break;
                            case "7":
                                 snode.addSon(node1);
                                 $(".option-edit-box").remove(); //移除追加人物编辑框
                                 //removeBox();
                                 break;
                            case "8":
                                snode.addDaughter(node1);
                                $(".option-edit-box").remove(); //移除追加人物编辑框
                                //removeBox();
                                break;
                            default:
                                break;
                        }
                     
                         bindContainer();
                        break;
                    case "edit":
                        for(var m in node1){
                            snode[m]=node1[m];
                        }
                        console.log(snode.name);
                        var $n= $("[nodeid="+snode.id+"]");
                        $n.find(".ctr-figure-image>img").attr("src",snode.avatar);
                        $n.find(".ctr-figure-name").text(snode.name);
                        $n.trigger("click");
                        break;
                    default:
                        break;

                } 
        }

    
        function allDraw() {
         
            if(!$jiapu)
            {
                return ;
            }
            drawed = {};
            nodePositions = {};
            jpnodes = [], geneIndex = {}, charnodes = {}, moveNodes = {};
            families = {};
            onlyFamilies = {};
            geneFamilies = {};
            nodesById={};
     
            var id = $root['id'];
            $(".tree-node-info").remove();
            var n = $nodes[id];
            nodeNumber =$nodeIds.length;
            
            var node = db2treeNode(n);
            node.gene = parseInt(n.shidai);
            //获得屏幕的中间
            var screen = window.screen;
            console.log(screen);
            node.y = 50;  
            node.x = 100; ; 
            node.wzchar = "05";
            var snode = null; //最后选择的 Node
            jpnodes[jpnodes.length] = node;
            addNodes($nodes[id], node);
            for(var j=0;j<$nodeIds.length;j++)
            {
                var n = $nodes[$nodeIds[j]];// sortNodes[id];
                if(!n){
                    debugger;
                }
                if(n.enable!=0){
                    var n1 = db2treeNode(n);
                    addNodes(n, n1);
                }
            }
            snode = node;
            removeBox();
            $("#view-total").text(jpnodes.length);
            htmlScale();
            setNodeCenter(node);
        }

        function setNodeCenter(node){
           var width = document.body.clientWidth;// document.body.clientWidth;
           var height = $(".move1").height();
            var div = $("#translate-group");

            var x = div.offset();
  
            $div = $("[nodeid=" + node.id + "]");

            var cx = $div.position().left;
            var cy = $div.position().top;
            $snode1= nodesById[node.id];
            var x1=width / 2 - $snode1.x -(nwidth/2);
            var y1= 180 - cy-(nheight);
            //alert(x1*currentScale);
            //debugger;
            setTimeout(function(){
                div.css("left", x1*currentScale);
                div.css("top", y1*currentScale);
                AfterMoveLink();    
                console.log("left:["+x1*currentScale+"] top:["+y1*currentScale+"]");
            },1000);
            
            if($(".ajp_scale").length>0){
                 $(".ajp_scale").css({"left": (-x1)+"px"});
            }
            console.log(x1*currentScale);
        }


         function htmlScale() {
            var html = "";
            var zore=false;
            var g={};
            for(var j=0;j<$nodeIds.length;j++)
            {
                var n =$nodeIds[j];
                var n1 = $nodes[ n].shidai;
                if(!g[n1]){
                    g[n1]=1;
                    var cnumber = chineseNumber[n1];
                    if(n1<1) continue;
                    var cc = cnumber.length > 1 ? "height:"+(cnumber.length+2)+ "em":"";
                    
                    if(cnumber.indexOf("一十")==0){
                       
                        cnumber= cnumber.substr(1);
                    }
                    html += '<li class="sc_item" scalegene="' + $nodes[ n].shidai + '"><div class="text_size_big"><span style="'+cc+'">第' + cnumber + '世</span></div><div class="text_size_small"><span>' + n1 + '</span></div></li>';
                }
           }
            $(".ajp_scale_mian").find("ul").html(html);
            var ctr = '#translate-group',  mian = '.ajp_scale_mian', sc_item = '.sc_item';
            var h = nheight * (1 + ysf);
            if(nodeSmall==1){
                    //h+=3;
            }
            $(mian).find(sc_item).css({ 'height': h + 'px', 'line-height': h + 'px' });
            $(mian).find(sc_item).children('.text_size_big').css({ 'height': h + 'px' });
            //获取位置
            //var x =   $('#first').position().top;
            $('.ajp_scale').css({ transform: 'translateY(' + 0 + 'px)' });
        }
        function addShidaiNav(shidai){
                var cnumber = chineseNumber[shidai];
                var cc = cnumber.length > 1 ? "height:"+(cnumber.length+2)+ "em":"";
                if(cnumber.indexOf("一十")==0){
                    cnumber= cnumber.substr(1);
                }
                html = '<li class="sc_item" scalegene="' + shidai + '"><div class="text_size_big"><span style="'+cc+'">第' + cnumber + '世</span></div><div class="text_size_small"><span>' + shidai + '</span></div></li>';
                $(".ajp_scale_mian").find("ul").append(html);
                var ctr = '#translate-group',  mian = '.ajp_scale_mian', sc_item = '.sc_item';
                var h = nheight * (1 + ysf);
                if(nodeSmall==1){
                    h+=3;
                }
                
                $(mian).find(sc_item).css({ 'height': h + 'px', 'line-height': h + 'px' });
                $(mian).find(sc_item).children('.text_size_big').css({ 'height': h + 'px' });
        }

        $(function(){
             $(".item-class-record").live("click",function(e){
                var nodeid =snode.id;
                var jiapuid= $jiapu.id;
                nodeAppendEdit("/index.php?a=jiapusub&type=recordEdit&jiapu="+jiapuid+"&nodeid="+nodeid);
             });
            $(".item-class-family").live("click",function(e){
                var nodeid =snode.id;
                var jiapuid= $jiapu.id;
                nodeAppendEdit("/index.php?a=jiapusub&type=familyEdit&jiapu="+jiapuid+"&nodeid="+nodeid);
            });
            $(".item-class-fangxi").live("click",function(e){
                var nodeid =snode.id;
                var jiapuid= $jiapu.id;
                nodeAppendEdit("/index.php?a=jiapusub&type=fangxiEdit&jpguid="+ $jiapu.guid+"&jiapu="+jiapuid+"&nodeid="+nodeid);
            });

            $(".item-class-mother").live("click",function(e){
                var nodeid =snode.id;
                var jiapuid= $jiapu.id;
                nodeAppendEdit("/index.php?a=jiapusub&type=motherEdit&jpguid="+$jiapu.guid+"&nodeid="+nodeid);
            });
        });



        var nodeAppendEdit=function(url){
            layer.closeAll();
            layer.open({
                    type: 2,
                    title: "",
                    shadeClose: false,
                    closeBtn: 0,
                    shade: 0.3,
                    maxmin: false, //开启最大化最小化按钮
                    area: ['900px', '570px'],
                    content: url,
            });
        };
        var goAction,goType;
        //节点详情
        var nodeDetail=function(action,nodeid,type,sort){
            layer.closeAll();
            if(type==2){
                if(!confirm("您确认需要添加根节点上级吗？添加完上级后会重新刷新网页，所有族人字辈都将重新进行匹配"))
                {
                    return ;
                }
            }
            goAction= action;
            goType=type;
            layer.open({
                    type: 2,
                    title: "",
                    shadeClose: false,
                    closeBtn: 0,
                    shade: 0.3,
                    maxmin: false, //开启最大化最小化按钮
                    area: ['900px', '570px'],
                    content: '/index.php?a=jiapu&type=zupunode&action='+action+"&nodeid="+nodeid+"&sptype="+type+"&sort="+sort,
            });
        };
         